package com.wetool.wechat.model.official.menu;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * 一级菜单按钮
 */
@Data
public class MenuButton extends AbstractMenuButton {

    /**
     * 二级菜单数组，个数应为1~5个
     */
    @JsonProperty(value = "sub_button")
    private List<SubMenuButton> subMenuButtons;


    public MenuButton(ButtonType type, String name) {
        super(type, name);
        this.subMenuButtons = new ArrayList<>();
    }

    public MenuButton(ButtonType type, ButtonKey key, String name) {
        this(type, name);
        this.key = key.name();
    }

    public MenuButton(ButtonType type, String name, String url) {
        super(type, name);
        this.url = url;
        this.subMenuButtons = new ArrayList<>();
    }

    public MenuButton(ButtonType type, ButtonKey buttonKey, String name, String url) {
        this(type, name, url);
        this.key = buttonKey.name();
    }

    /**
     * @param subMenuButton
     * @return
     */
    public boolean addButton(SubMenuButton subMenuButton) {
        if (this.subMenuButtons.size() > 5) {
            return false;
        }

        subMenuButtons.add(subMenuButton);

        return true;
    }

}




